import * as echarts from "echarts";
import { useEffect, useRef } from "react";

// 获取渲染图表的dom节点
// const chartDom = document.getElementById("main");
const BarChart = (props) => {
  const charRef = useRef(null);
  useEffect(() => {
    const chartDom = charRef.current;
    // 图表初始化生成图表实例对象
    const myChart = echarts.init(chartDom);
    // 准备图表参数
    const option = {
      title: {
        text: props.title,
      },
      xAxis: {
        type: "category",
        data: ["Vue", "Angular", "React"],
      },
      yAxis: {
        type: "value",
      },
      series: [
        {
          data: [120, 200, 250],
          type: "bar",
        },
      ],
    };

    // 使用图表参数完成图表渲染
    option && myChart.setOption(option);
  }, []);

  return <div ref={charRef} style={{ width: 600, height: 400 }}></div>;
};

export default BarChart
